<template>
	<view>
		<!-- 导航栏 -->
		<uni-nav-bar :fixed="true" :border="false" :statusBar="true" :backgroundColor="'#ff6a6a'" :color="'#fff'"
			:height="50">
			<template #left>
				<view class="right-icon" @click="toPath('messages')">
					<uni-icons type="notification" size="24" color="#fff"></uni-icons>
				</view>
			</template>
			<view class="nav-center">
				<!-- 搜索框 -->
				<view class="search-bar">
					<view class="search-input" @click="toPath('search')">
						<uni-icons type="search" size="18" color="#999"></uni-icons>
						<input class="input" type="text" placeholder="搜索商品/商家" placeholder-style="color: #999;" />
					</view>
				</view>
			</view>
		</uni-nav-bar>
		<!-- 轮播图 -->
		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item>
				<view class="swiper-item">
					<image mode="aspectFill" style="width: 100%;"
						src="https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da" />
				</view>
			</swiper-item>
			<swiper-item>
				<view class="swiper-item">
					<image mode="aspectFill" style="width: 100%;"
						src="https://images.unsplash.com/photo-1607082348824-0a96f2a4b9da" />
				</view>
			</swiper-item>
		</swiper>

		<!-- 图标导航 -->
		<view class="icon-grid" style="margin: 16px;">
			<uni-grid :column="6">
				<uni-grid-item>
					<view class="icon-grid-item" @click="toPath('merchant')">
						<uni-icons type="shop" size="24" color="#409EFF"></uni-icons>
						<text class="label">商家</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="icon-grid-item" @click="toPath('group')">
						<uni-icons type="staff" size="24" color="#67C23A"></uni-icons>
						<text class="label">拼团</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="icon-grid-item" @click="toPath('flash')">
						<uni-icons type="notification" size="24" color="#E6A23C"></uni-icons>
						<text class="label">秒杀</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="icon-grid-item" @click="toPath('rush')">
						<uni-icons type="cart" size="24" color="#ff6a6a"></uni-icons>
						<text class="label">抢购</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="icon-grid-item" @click="toPath('bargain')">
						<uni-icons type="heart" size="24" color="#F56C6C"></uni-icons>
						<text class="label">砍价</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="icon-grid-item" @click="toPath('coupon')">
						<uni-icons type="gift" size="24" color="#909399"></uni-icons>
						<text class="label">优惠券</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>

		<view class="activity-section">
			<view class="section-header">
				<text class="section-title">限时秒杀</text>
				<view class="section-more" @click="toPath('flash')">
					<text>更多</text>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
			</view>
			<view class="grid">
				<product-card tag-type="seckill"
					image-url="https://images.unsplash.com/photo-1526170375885-4d8ecf77b99f" title="便携式蓝牙音箱"
					price="49.9" original-price="99.9" />
				<product-card tag-type="seckill"
					image-url="https://images.unsplash.com/photo-1572635196237-14b3f281503f" title="时尚太阳镜" price="39.9"
					original-price="89.9" />
			</view>
		</view>

		<view class="activity-section">
			<view class="section-header">
				<text class="section-title">抢购专区</text>
				<view class="section-more" @click="toPath('rush')">
					<text>更多</text>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
			</view>
			<view class="grid">
				<product-card tag-type="rush" image-url="https://images.unsplash.com/photo-1505740420928-5e560c06d30e"
					title="无线降噪耳机" price="199.9" original-price="299.9" :rush-stock="50" :rush-count="158" />
				<product-card tag-type="rush" image-url="https://images.unsplash.com/photo-1542291026-7eec264c27ff"
					title="运动跑鞋" price="299.9" original-price="499.9" :rush-stock="30" :rush-count="245" />
			</view>
		</view>

		<view class="activity-section">
			<view class="section-header">
				<text class="section-title">拼团活动</text>
				<view class="section-more" @click="toPath('group')">
					<text>更多</text>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
			</view>
			<view class="grid">
				<product-card tag-type="group" image-url="https://images.unsplash.com/photo-1631729371254-42c2892f0e6e"
					title="便携式加湿器" price="39.9" original-price="69.9" :group-people="2" :group-count="36" />
				<product-card tag-type="group" image-url="https://images.unsplash.com/photo-1583394838336-acd977736f90"
					title="多功能笔记本" price="15.9" original-price="29.9" :group-people="3" :group-count="52" />
			</view>
		</view>

		<!-- 砍价活动 -->
		<view class="activity-section">
			<view class="section-header">
				<text class="section-title">砍价优惠</text>
				<view class="section-more" @click="toPath('bargain')">
					<text>更多</text>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
			</view>
			<view class="grid">
				<product-card tag-type="bargain"
					image-url="https://images.unsplash.com/photo-1523275335684-37898b6baf30" title="简约智能手表" price="89.9"
					original-price="129.9" :bargain-count="125" />
				<product-card tag-type="bargain" image-url="https://images.unsplash.com/photo-1560343090-f0409e92791a"
					title="便携式化妆镜" price="19.9" original-price="39.9" :bargain-count="98" />
			</view>
		</view>

		<!-- 热门商家 -->
		<view class="activity-section">
			<view class="section-header">
				<text class="section-title">热门商家</text>
				<view class="section-more" @click="toPath('merchant')">
					<text>更多</text>
					<uni-icons type="right" size="14" color="#999"></uni-icons>
				</view>
			</view>
			<merchant-card logo="https://images.unsplash.com/photo-1542838132-92c53300491e" name="名创优品旗舰店"
				:is-official="true" :rating="4.8" :sales="5000" :tags="['日本设计', '简约生活']"
				:promotions="['满200减30', '新人首单立减20元']" @click="toMerchantDetail" />
			<merchant-card logo="https://images.unsplash.com/photo-1556740738-b6a63e27c4df" name="优品生活馆"
				:rating="4.6" :sales="3200" :tags="['精选家居', '品质保证']"
				:promotions="['满100减15', '新店优惠券50元']" @click="toMerchantDetail" />
		</view>
		<scroll-view scroll-y class="content">
			<!-- 猜你喜欢 -->
			<view class="activity-section">
				<view class="section-header">
					<text class="section-title">猜你喜欢</text>
				</view>
				<view class="grid">
					<product-card tag-type="discount"
						image-url="https://images.unsplash.com/photo-1523275335684-37898b6baf30" title="简约智能手表"
						price="99.9" original-price="129.9" />
					<product-card tag-type="discount"
						image-url="https://images.unsplash.com/photo-1631729371254-42c2892f0e6e" title="便携式加湿器"
						price="39.9" original-price="59.9" />
					<product-card tag-type="group"
						image-url="https://images.unsplash.com/photo-1583394838336-acd977736f90" title="多功能笔记本"
						price="12.9" original-price="19.9" :group-people="2" :group-count="28" />
					<product-card tag-type="bargain"
						image-url="https://images.unsplash.com/photo-1560343090-f0409e92791a" title="便携式化妆镜"
						price="19.9" original-price="29.9" :bargain-count="45" />
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script setup>
	const toMerchantDetail = () => {
		uni.navigateTo({
			url: '/subpackage_merchant/merchant/merchant_detail'
		});
	};
	const toPath = (e) => {
		let url = '';
		switch (e) {
			case 'search':
				url = '/pages/home/search';
				break;
			case 'merchant':
				url = '/subpackage_merchant/merchant/merchant_categories';
				break;
			case 'group':
				url = '/subpackage_activity/activity/group_buying';
				break;
			case 'flash':
				url = '/subpackage_activity/activity/flash_sale';
				break;
			case 'bargain':
				url = '/subpackage_activity/activity/bargain';
				break;
			case 'coupon':
				url = '/subpackage_user/user/coupons';
				break;
			case 'category':
				url = '/subpackage_category/category/category_list';
				break;
			case 'messages':
				url = '/subpackage_msg/msg/messages';
				break;
			case 'rush':
				url = '/subpackage_activity/activity/rush';
				break;
			default:
				break;
		}
		uni.navigateTo({
			url: url
		})
	}
</script>

<style lang="scss" scoped>
	.nav-center {
		flex: 1;
		padding: 0 12px;
		display: flex;
		align-items: center;
	}

	.right-icon {
		padding: 0 12px;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	:deep(.uni-navbar__header) {
		font-size: 180px;
		font-weight: bold;
	}

	.search-bar {
		background: rgba(255, 255, 255, 0.95);
		border-radius: 20px;
		padding: 6px 12px;

		.search-input {
			display: flex;
			align-items: center;

			.input {
				flex: 1;
				margin-left: 8px;
				font-size: 14px;
				color: #333;
			}
		}
	}

	.swiper {
		margin: 16px;
		height: 180px;
		border-radius: 8px;
		overflow: hidden;

		image {
			width: 100%;
		}
	}

	.icon-grid {
		padding: 12px;
		border-radius: 12px;
		background-color: #fff;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);

		:deep(.uni-grid--border) {
			border: none !important;
		}

		:deep(.uni-grid-item--border) {
			border: none !important;
		}

		.icon-grid-item {
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			padding: 6px 0;
			transition: all 0.3s ease;

			&:active {
				transform: scale(0.95);
			}

			.uni-icons {
				margin-bottom: 4px;
				transition: transform 0.3s ease;
			}

			.label {
				font-size: 11px;
				color: #333;
				margin-top: 2px;
				transition: color 0.3s ease;
			}

			&:hover {
				.uni-icons {
					transform: translateY(-2px);
				}

				.label {
					color: var(--primary-color, #409EFF);
				}
			}
		}
	}

	.activity-section {
		margin: 16px 12px;

		.section-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 12px;

			.section-title {
				font-size: 16px;
				font-weight: bold;
			}

			.section-more {
				display: flex;
				align-items: center;
				color: #999;
				font-size: 12px;
			}
		}

		.grid {
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			gap: 12px;
		}

		.merchant-card {
			background: #fff;
			border-radius: 12px;
			padding: 12px;
			display: flex;
			align-items: center;
			margin-bottom: 12px;
			box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
			transition: all 0.3s;

			&:hover {
				transform: translateY(-2px);
				box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
			}

			.merchant-logo {
				width: 60px;
				height: 60px;
				margin-right: 12px;
				border-radius: 8px;
				overflow: hidden;

				image {
					width: 100%;
					height: 100%;
					object-fit: cover;
				}
			}

			.merchant-info {
				flex: 1;

				.merchant-name {
					font-size: 16px;
					font-weight: bold;
					margin-bottom: 4px;
				}

				.merchant-desc {
					font-size: 12px;
					color: #666;
					margin-bottom: 8px;
				}

				.merchant-tags {
					display: flex;
					gap: 8px;

					.tag {
						padding: 2px 8px;
						border-radius: 4px;
						font-size: 12px;

						&.tag-primary {
							background-color: rgba(64, 158, 255, 0.1);
							color: #409eff;
						}

						&.tag-success {
							background-color: rgba(103, 194, 58, 0.1);
							color: #67c23a;
						}
					}
				}
			}
		}
	}
</style>